<?php
header('Content-Type:application/json;charset=UTF-8');
$conn = mysqli_connect('localhost','root','root','project');
if(!$conn){
    echo json_encode(['code'=>0,'msg'=>'数据库连接失败']);
}
$sql = "select dept_name,count(*) as total from employee join department on employee.department_id = department.id group by department_id";
$query = mysqli_query($conn,$sql);
$result = mysqli_fetch_all($query,MYSQLI_ASSOC);
$xData = [];
$yData = [];
foreach($result as $val){
    array_push($xData,$val['dept_name']);
    array_push($yData,$val['total']);
}
echo json_encode(['code'=>1,'msg'=>'员工部门分布','data' => [
    'xData' => $xData,
    'yData' => $yData,
]]);